﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Security.Permissions;
//using AjaxControlToolkit;
using System.Drawing;

namespace GandA.Web.UI.Controls
{
    [
    AspNetHostingPermission(SecurityAction.Demand,
        Level = AspNetHostingPermissionLevel.Minimal),
    AspNetHostingPermission(SecurityAction.InheritanceDemand,
        Level = AspNetHostingPermissionLevel.Minimal),
    ]
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:TextBoxPassword runat=server></{0}:TextBoxPassword>")]
    [ToolboxBitmap(typeof(TextBoxPassword), "TextBoxPassword.png")]
    public class TextBoxPassword : CompositeControl
    {
        //private System.Web.UI.WebControls.TextBox TxtControl;
        //private System.Web.UI.WebControls.RequiredFieldValidator rfvControl;
        //private AjaxControlToolkit.ValidatorCalloutExtender vceControl;
        //private PasswordStrength psControl;
        //private static readonly object EventTextChanged = new object();

        //#region Propiedades
        //[Bindable(true)]
        //[Category("Default")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public string Text
        //{
        //    get
        //    {
        //        EnsureChildControls();
        //        return TxtControl.Text;
        //    }

        //    set
        //    {
        //        EnsureChildControls();
        //        TxtControl.Text = value;
        //    }
        //}

        //[Bindable(true)]
        //[Category("Defult")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public int MaxLength
        //{
        //    get
        //    {
        //        EnsureChildControls();
        //        return TxtControl.MaxLength;
        //    }

        //    set
        //    {
        //        EnsureChildControls();
        //        TxtControl.MaxLength = value;
        //    }
        //}

        //[Bindable(true)]
        //[Category("Layout")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public override Unit Width
        //{
        //    get
        //    {
        //        EnsureChildControls();
        //        return TxtControl.Width;
        //    }

        //    set
        //    {
        //        EnsureChildControls();
        //        TxtControl.Width = value;
        //    }
        //}

        //[Bindable(true)]
        //[Category("Layout")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public override Unit Height
        //{
        //    get
        //    {
        //        EnsureChildControls();
        //        return TxtControl.Height;
        //    }

        //    set
        //    {
        //        EnsureChildControls();
        //        TxtControl.Height = value;
        //    }
        //}

        //[Bindable(true)]
        //[Category("Accessibility")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public override short TabIndex
        //{
        //    get
        //    {
        //        EnsureChildControls();
        //        return TxtControl.TabIndex;
        //    }

        //    set
        //    {
        //        EnsureChildControls();
        //        TxtControl.TabIndex = value;
        //    }
        //}

        //[Bindable(true)]
        //[Category("Appearance")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public override string CssClass
        //{
        //    get
        //    {
        //        EnsureChildControls();
        //        return TxtControl.CssClass;
        //    }

        //    set
        //    {
        //        EnsureChildControls();
        //        TxtControl.CssClass = value;
        //    }
        //}

        //[Bindable(true)]
        //[Category("Appearance")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public string HighlightCssClass
        //{
        //    get
        //    {
        //        EnsureChildControls();
        //        return vceControl.HighlightCssClass;
        //    }

        //    set
        //    {
        //        EnsureChildControls();
        //        vceControl.HighlightCssClass = value;
        //    }
        //}

        //[Bindable(true)]
        //[Category("Appearance")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public string CssClassValidator
        //{
        //    get
        //    {
        //        EnsureChildControls();
        //        return vceControl.CssClass;
        //    }

        //    set
        //    {
        //        EnsureChildControls();
        //        vceControl.CssClass = value;
        //    }
        //}

        //[Bindable(true)]
        //[Category("Validator")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public string ErrorMessage
        //{
        //    get
        //    {
        //        EnsureChildControls();
        //        return rfvControl.ErrorMessage;
        //    }

        //    set
        //    {
        //        EnsureChildControls();
        //        rfvControl.ErrorMessage = value;
        //    }
        //}

        //[Bindable(true)]
        //[Category("Validator")]
        //[DefaultValue(false)]
        //[Localizable(true)]
        //public bool EnabledValidator
        //{
        //    get
        //    {
        //        EnsureChildControls();
        //        return rfvControl.Enabled;
        //    }
        //    set
        //    {
        //        EnsureChildControls();
        //        rfvControl.Enabled = value;
        //    }
        //}

        //[Bindable(true)]
        //[Category("Controls")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public System.Web.UI.WebControls.TextBox ControlTextBox
        //{
        //    get { EnsureChildControls(); return TxtControl; }
        //}

        //[Bindable(true)]
        //[Category("Controls")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public System.Web.UI.WebControls.RequiredFieldValidator ControlRequiereFieldValidator
        //{
        //    get { EnsureChildControls(); return rfvControl; }
        //}

        //[Bindable(true)]
        //[Category("PasswordStrength")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public DisplayPosition DisplayPosition
        //{
        //    get { EnsureChildControls(); return psControl.DisplayPosition; }
        //    set { psControl.DisplayPosition = value; }
        //}

        //[Bindable(true)]
        //[Category("PasswordStrength")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public StrengthIndicatorTypes StrengthIndicatorType
        //{
        //    get { EnsureChildControls(); return psControl.StrengthIndicatorType; }
        //    set { psControl.StrengthIndicatorType = value; }
        //}

        //[Bindable(true)]
        //[Category("PasswordStrength")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public int PreferredPasswordLength
        //{
        //    get { EnsureChildControls(); return psControl.PreferredPasswordLength; }
        //    set { psControl.PreferredPasswordLength = value; }
        //}

        //[Bindable(true)]
        //[Category("PasswordStrength")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public string PrefixText
        //{
        //    get { EnsureChildControls(); return psControl.PrefixText; }
        //    set { psControl.PrefixText = value; }
        //}
        
        //[Bindable(true)]
        //[Category("PasswordStrength")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public string TextCssClass
        //{
        //    get { EnsureChildControls(); return psControl.TextCssClass; }
        //    set { psControl.TextCssClass = value; }
        //}    
         
        //[Bindable(true)]
        //[Category("PasswordStrength")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public int MinimumNumericCharacters
        //{
        //    get { EnsureChildControls(); return psControl.MinimumNumericCharacters; }
        //    set { psControl.MinimumNumericCharacters = value; }
        //}
        
        //[Bindable(true)]
        //[Category("PasswordStrength")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public int MinimumSymbolCharacters
        //{
        //    get { EnsureChildControls(); return psControl.MinimumSymbolCharacters; }
        //    set { psControl.MinimumSymbolCharacters = value; }
        //}
         
        //[Bindable(true)]
        //[Category("PasswordStrength")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public bool RequiresUpperAndLowerCaseCharacters
        //{
        //    get { EnsureChildControls(); return psControl.RequiresUpperAndLowerCaseCharacters; }
        //    set { psControl.RequiresUpperAndLowerCaseCharacters = value; }
        //}

        //[Bindable(true)]
        //[Category("PasswordStrength")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public string TextStrengthDescriptions
        //{
        //    get { EnsureChildControls(); return psControl.TextStrengthDescriptions; }
        //    set { psControl.TextStrengthDescriptions = value; }
        //}

        //[Bindable(true)]
        //[Category("PasswordStrength")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public string TextStrengthDescriptionStyles
        //{
        //    get { EnsureChildControls(); return psControl.TextStrengthDescriptionStyles; }
        //    set { psControl.TextStrengthDescriptionStyles = value; }
        //}
            
        //[Bindable(true)]
        //[Category("PasswordStrength")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public string StrengthStyles
        //{
        //    get { EnsureChildControls(); return psControl.StrengthStyles; }
        //    set { psControl.StrengthStyles = value; }
        //}

        //[Bindable(true)]
        //[Category("Behavior")]
        //[DefaultValue("")]
        //[Localizable(true)]
        //public bool AutoPostBack
        //{
        //    get
        //    {
        //        EnsureChildControls();
        //        return TxtControl.AutoPostBack;
        //    }

        //    set
        //    {
        //        EnsureChildControls();
        //        TxtControl.AutoPostBack = value;
        //    }
        //}
        //#endregion

        //#region Metodos
        //protected override void RecreateChildControls()
        //{
        //    EnsureChildControls();
        //}

        //protected override void CreateChildControls()
        //{
        //    Controls.Clear();

        //    TxtControl = new System.Web.UI.WebControls.TextBox();
        //    TxtControl.ID = "TxtControl1";
        //    TxtControl.TextMode = TextBoxMode.Password;
        //    TxtControl.TextChanged += _textBox_TextChanged;

        //    rfvControl = new RequiredFieldValidator();
        //    rfvControl.ID = "rfValidator1";
        //    rfvControl.ControlToValidate = TxtControl.ID;
        //    rfvControl.Text = "Failed validation.";
        //    rfvControl.Display = ValidatorDisplay.None;
        //    rfvControl.SetFocusOnError = true;
        //    rfvControl.ErrorMessage = "Campo requrido";
        //    rfvControl.Enabled = false;

        //    vceControl = new ValidatorCalloutExtender();
        //    vceControl.ID = "vceControl1";
        //    vceControl.TargetControlID = rfvControl.ID;
        //    vceControl.HighlightCssClass = "validatorCalloutHighlight";

        //    psControl = new PasswordStrength();
        //    psControl.ID = "psControl1";
        //    psControl.TargetControlID = TxtControl.ID;
        //    psControl.DisplayPosition = DisplayPosition.RightSide;
        //    psControl.StrengthIndicatorType = StrengthIndicatorTypes.Text;
        //    psControl.PreferredPasswordLength = 10;
        //    psControl.PrefixText = "Seguridad:";
        //    psControl.TextCssClass = "TextIndicator_TextBox1";
        //    psControl.MinimumNumericCharacters = 0;
        //    psControl.MinimumSymbolCharacters = 0;
        //    psControl.RequiresUpperAndLowerCaseCharacters = false;
        //    psControl.TextStrengthDescriptions = "Muy pobre; Débil; Medio; Fuerte; Excelente";
        //    psControl.TextStrengthDescriptionStyles = "TextIndicator_TextBox1_Strength1;TextIndicator_TextBox1_Strength2;TextIndicator_TextBox1_Strength3;TextIndicator_TextBox1_Strength4;TextIndicator_TextBox1_Strength5";
        //    psControl.StrengthStyles = "TextIndicator_TextBox1_Strength1;TextIndicator_TextBox1_Strength2;TextIndicator_TextBox1_Strength3;TextIndicator_TextBox1_Strength4;TextIndicator_TextBox1_Strength5";
                        
        //    this.Controls.Add(TxtControl);
        //    this.Controls.Add(rfvControl);
        //    this.Controls.Add(vceControl);
        //    this.Controls.Add(psControl);
        //}

        //protected override void OnPreRender(EventArgs e)
        //{
        //    bool linkIncluded = false;
        //    foreach (Control c in Page.Header.Controls)
        //    {
        //        if (c.ID == "StyleControls")
        //        {
        //            linkIncluded = true;
        //        }
        //    }
        //    if (!linkIncluded)
        //    {
        //        HtmlGenericControl csslink = new HtmlGenericControl("link");
        //        csslink.ID = "StyleControls";
        //        csslink.Attributes.Add("href",
        //                               Page.ClientScript.GetWebResourceUrl(this.GetType(), "GandA.Web.UI.Controls.Controls.css"));
        //        csslink.Attributes.Add("type", "text/css");
        //        csslink.Attributes.Add("rel", "stylesheet");
        //        Page.Header.Controls.Add(csslink);
        //    }

        //    base.OnPreRender(e);
        //}

        //protected override void Render(HtmlTextWriter writer)
        //{
        //    AddAttributesToRender(writer);

        //    writer.AddAttribute(
        //        HtmlTextWriterAttribute.Cellpadding,
        //        "0", false);
        //    writer.RenderBeginTag(HtmlTextWriterTag.Table);
        //    writer.RenderBeginTag(HtmlTextWriterTag.Tr);

        //    writer.RenderBeginTag(HtmlTextWriterTag.Td);
        //    TxtControl.RenderControl(writer);
        //    rfvControl.RenderControl(writer);
        //    vceControl.RenderControl(writer);
        //    psControl.RenderControl(writer);
        //    writer.RenderEndTag();

        //    writer.RenderEndTag();
        //    writer.RenderEndTag();
        //}

        //// The Chaged event.
        //[
        //Category("Action"),
        //Description("Se dispara cuando el valor del text es cambiado")
        //]
        //public event EventHandler TextChanged
        //{
        //    add
        //    {
        //        Events.AddHandler(EventTextChanged, value);
        //    }
        //    remove
        //    {
        //        Events.RemoveHandler(EventTextChanged, value);
        //    }
        //}

        //// The method that raises the Submit event.
        //protected virtual void OnTextChanged(EventArgs e)
        //{
        //    EventHandler ChangedHandler =
        //        (EventHandler)Events[EventTextChanged];
        //    if (ChangedHandler != null)
        //    {
        //        ChangedHandler(this, e);
        //    }
        //}

        //// Handles the Changed event of the TextBox and raises
        //// the TextChanged event.
        //private void _textBox_TextChanged(object source, EventArgs e)
        //{
        //    OnTextChanged(EventArgs.Empty);
        //}
        //#endregion
    }
}
